home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / spellr20.zip / SPELLR.M < prev   
Text File  |  1988-09-11  |  16KB  |  546 lines

  1. (extern    add_to_path    next_error _check_warnings)
  2. ;=======================================================================
  3. ; This routine spell checks the file in the  current  buffer  using  the
  4. ; current file in the buffer.
  5. ;=======================================================================
  6. (macro spellr (
  7.     (string    
  8.         file_name            ;** The name of the file we're compiling.
  9.         extension            ;** The file name extension
  10.            command_line        ;** The compile command line.
  11.            path                 ;** The path of the file we're compiling.
  12.            old_path            ;** The original path we were on.
  13.            error_file            ;** The file to put error information in.
  14.     )
  15.     (int       
  16.         loc                    ;** Generic index place holder.
  17.            ret_code            ;** Return code from DOS.
  18.            buffer_id            ;** Buffer ID of error buffer.
  19.            check_warnings        ;** Examine resule of compile for errors?
  20.         tab_length            ;** length of tab stops
  21.     )
  22. ;(pause_on_error 1)
  23.     (inq_names path extension file_name)
  24.     (= ret_code 1)
  25.     ;===================================================================
  26.     ; If the file has been modified, we want to make  sure  the  current
  27.     ; version gets spell checked, so we write it to disk.
  28.     ;===================================================================
  29.     (if (inq_modified) (
  30.         (int old_msg_level)
  31.         (= old_msg_level (inq_msg_level))
  32.         (set_msg_level 0)
  33.         (= ret_code (write_buffer))
  34.         (set_msg_level old_msg_level)
  35.     ))
  36.     (if (>= ret_code 0) (
  37.         ;===============================================================
  38.         ; Now we parse the filename off the path string making  sure  to
  39.         ; handle the possible presence of  forward  and  backward  slash
  40.         ; characters. We then replace  the  file_name's  extension  with
  41.         ; ".err" for redirection purposes.
  42.         ;===============================================================
  43.         (= path (substr path 1 (rindex path (substr path 3 1))))
  44.         (if (> (strlen path) 3)
  45.             (= path (substr path 1 (- (strlen path) 1)))
  46.         )
  47.         (= file_name (substr file_name 1 (- (index file_name ".") 1)))
  48.         (= error_file (+ file_name ".err"))
  49.         (= ret_code 0)
  50.         ;===============================================================
  51.         ; We want any file generated to end up in the file's  directory,
  52.         ; so we change to the directory where the file  is,  saving  the
  53.         ; current directory. We also make the file's drive  the  default
  54.         ; drive.
  55.         ;===============================================================
  56.         (getwd "" command_line)
  57.         (getwd path old_path)
  58.         (= old_path (+ (substr command_line 1 1) (substr old_path 2)))
  59.         (cd path)
  60.         (cd (substr path 1 2))
  61.         ;===============================================================
  62.         ; If there is already a buffer for the error file,  we  "create"
  63.         ; it (create_buffer returns the ID  of  a  buffer  that  already
  64.         ; existed) and the delete it immediately. Note that  under  some
  65.         ; very obscure circumstances, the create+buffer call could fail.
  66.         ; If it does, it'll return 0, which is an invalid buffer id.  We
  67.         ; check for this case since delete_buffer does not.
  68.         ;===============================================================
  69.         (if (= buffer_id (create_buffer "SpellR Err" error_file 1))
  70.             (delete_buffer buffer_id)
  71.         )
  72.         ;===============================================================
  73.         ; Get the current tab distance
  74.         ;===============================================================
  75.         (move_abs 0 1)
  76.         (= tab_length (distance_to_tab))
  77.         ;===============================================================
  78.         ; Output the command line and then execute it.
  79.         ;===============================================================
  80.         (sprintf command_line "spellr -t%d " tab_length)
  81.         (+= command_line file_name)
  82.         (if (strlen extension) (
  83.             (+= command_line ".")
  84.             (+= command_line extension)
  85.         ))
  86.         (+= command_line " >& ")
  87.         (+= command_line error_file)
  88.         (message command_line)
  89.         (= ret_code (dos command_line 0))
  90.         (if (> ret_code 0) (
  91.             (next_error)
  92.         ))
  93.         (del error_file)
  94.         (if (== ret_code 0)
  95.             (message "SpellR successful.")
  96.         )
  97.         (cd (substr old_path 3))
  98.         (cd (substr old_path 1 2))
  99.     ))
  100.     (returns ret_code)
  101. ))
  102. ;**
  103. ;**        BRIEF -- Basic Reconfigurable Interactive Editing Facility
  104. ;**
  105. ;**        Written by Dave Nanian and Michael Strickman.
  106. ;**
  107.  
  108. ;**        errorfix.m
  109. ;**
  110. ;**        This file contains the main driver and support macros for BRIEF's
  111. ;**    error location facility.
  112. ;**
  113.  
  114. #define    TRUE            1
  115. #define    FALSE            0
  116.  
  117. #define    WARNING        1
  118. #define    ERROR            2
  119.  
  120. (extern    add_to_path
  121.             center_line
  122.             _exit
  123. )
  124.  
  125. ;**
  126. ;**        next_error:
  127. ;**
  128. ;**        This routine is the engine for BRIEF's error location facility.  It
  129. ;**    reads in the error file and calls the appropriate routines to display
  130. ;**    either an individual error message or a window full of error message
  131. ;**    information.
  132. ;**
  133. ;**        If no parameter (or zero) is passed to next_error, the error file is
  134. ;**    read into a buffer and searched for error messages.  If the buffer is
  135. ;**    empty, the message "No errors." is displayed and the error buffer is
  136. ;**    removed.  If the buffer is not empty, and a message can be located, the
  137. ;**    text of the message is displayed on the message line, the cursor is placed
  138. ;**    on the first non-blank character of the line containing the error, and that
  139. ;**    line is centered in the window.  If no messages can be located, the error
  140. ;**    file is presented in a pop-up window.
  141. ;**
  142. ;**        If a "1" is passed to next_error, the error information is displayed in
  143. ;**    a window, with the current message highlighted.  If no messages could be
  144. ;**    recognised, the highlight is not displayed, and the cursor can be moved
  145. ;**    anywhere within the file.
  146. ;**
  147. ;**        If a "2" is passed to next_error, the error file is tested to see if
  148. ;**    any messages can be recognised.  If so, the same action is taken as with
  149. ;**    next_error 0.  If not, no message is displayed and the error file buffer
  150. ;**    is deleted.
  151. ;**
  152. ;**        In all cases, next_error returns 0 if no error was found, and non-zero
  153. ;**    if there was an error.
  154. ;**
  155.  
  156. (macro next_error
  157.     (
  158.         (int        error_buf
  159.                     curr_buf
  160.                     line
  161.                     col
  162.                     error_type
  163.                     more_errors
  164.                     prev_errors
  165.                     errors_exist
  166.                     action
  167.                     windowed
  168.                     _cancel_errorfix
  169.         )
  170.         (string    error_msg
  171.                     error_file
  172.                     buf_name
  173.                     parms
  174.                     error_extension
  175.         )
  176.         (global    _cancel_errorfix)
  177.  
  178.         (inq_names error_file error_extension buf_name)
  179.         (= curr_buf (inq_buffer))
  180.         (= _cancel_errorfix FALSE)
  181.  
  182.         (if (strlen error_extension) (
  183.             (= error_file (substr error_file 1 (- (rindex error_file ".") 1)))
  184.             (= error_extension (+ "." error_extension))
  185.         )
  186.         ;else
  187.         (
  188.             (= error_extension ".")
  189.         ))
  190.         (+= error_file ".err")
  191.         (= parms (+ (+ error_extension " ") buf_name))
  192.  
  193.         (if (! (= error_buf (create_buffer "Error File" error_file TRUE)))
  194.             (return FALSE)
  195.         )
  196.         (set_buffer error_buf)
  197.         (save_position)
  198.         (top_of_buffer)
  199.         (= errors_exist (end_of_buffer))
  200.         (restore_position)
  201.         (get_parm 0 action)
  202.  
  203.         (if (! errors_exist)
  204.             (
  205.                 (if (!= action 2)
  206.                     (message "No errors.")
  207.                 )
  208.             )
  209.         ;else
  210.             (
  211.                 (= windowed (== action 1))
  212.                 (save_position)
  213.                 (= more_errors (execute_macro (+ "_call_next " parms)))
  214.  
  215.                 (if (&& more_errors windowed)
  216.                     (execute_macro (+ "_call_prev " parms))
  217.                 ;else
  218.                     (
  219.                         (down)
  220.                         (save_position)
  221.                         (= prev_errors (execute_macro (+ "_call_prev " parms)))
  222.                         (restore_position)
  223.                         (restore_position)
  224.                         (save_position)
  225.                     )
  226.                 )
  227.                 (= errors_exist (|| more_errors prev_errors))
  228.  
  229.                 (if (= windowed (&& (!= action 2) (|| windowed (! errors_exist))))
  230.                     (
  231.                         (int    lines
  232.                                 cols
  233.                         )
  234.                         (keyboard_push)
  235.                         (assign_to_key "<Enter>" "_exit")
  236.                         (assign_to_key "<Esc>" "_error_cancel")
  237.                         (assign_to_key "<Left>" "left")
  238.                         (assign_to_key "<Right>" "right")
  239.                         (assign_to_key "<Home>" "beginning_of_line")
  240.                         (assign_to_key "<End>" "end_of_line")
  241.  
  242.